<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:insert="~{include :: header('用户分配角色')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
        <form id="form-user-add" class="form-horizontal">
            <input type="hidden" id="managerId" name="managerId" th:value="${manager.managerId}">
            <h4 class="form-header h4">基本信息</h4>
            <hr>
            <div class="row">
            	<div class="col-sm-5">
                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-sm-right">用户名称</label>
                        <div class="col-sm-8">
                            <input name="managerName" class="form-control" type="text" disabled th:value="${manager.managerName}">
                        </div>
                    </div>
                </div>
                <div class="col-sm-5">
                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-sm-right">登录账号</label>
                        <div class="col-sm-8">
                            <input name="loginName" class="form-control" type="text" disabled th:value="${manager.loginName}">
                        </div>
                    </div>
                </div> 
            </div>
            <h4 class="form-header h4">分配角色</h4>
            <hr>
            <div class="row">
                <div class="col-sm-12">
                    <div class="col-sm-12 select-table table-striped">
					    <table id="bootstrap-table" class="table-striped"></table>
					</div>
                </div>
            </div>
        </form>
    </div>
      
    <div class="row">
        <label class="col-sm-2"></label>
                <div class="col-sm-10">
            <button type="button" class="btn btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
	<th:block th:insert="~{include :: footer}" />
    <th:block th:insert="~{include :: bootstrap-table-js}" />
	<script th:inline="javascript">
	    var prefix = "/manager";
	    var managerRoles = [[${managerRoles}]]
	    
	    $(function() {
		    var options = {
		        url: "/role/list.json",
		        sortName: "roleSort",
		        showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                clickToSelect: true,
		        columns: [{
		            checkbox: true,
		            formatter:function (value, row, index) {
		            	for (var i = 0; i < managerRoles.length; i++) {
		            	    if (managerRoles[i].roleId == row.roleId) {
		            	        return { checked: true };
		            	    }
		            	}
		            	return { checked: false };
		            }
		        },
		        {
		            field: 'roleId',
		            title: '角色编号'
		        },
		        {
		            field: 'roleName',
		            title: '角色名称',
		            sortable: true
		        },
		        {
		            field: 'roleKey',
		            title: '权限字符',
		            sortable: true
		        },
		        {
		            field: 'createTime',
		            title: '创建时间',
		            sortable: true
		        }]
		    };
		    $.table.init(options);
		});
	    
	    /* 添加角色-提交 */
        function submitHandler(index, layero){
        	var rows = $.table.selectFirstColumns();
        	var data = { "managerId": $("#managerId").val(), "roleIds": rows.join() };
			$.operate.saveTab(prefix + "/authRole.json", data);
        }
    </script>
</body>
</html>